package com.community.process._1010.controller;


import com.community.process._1010.common.api.CommonResult;
import com.community.process._1010.dao.view.ProcessIngredientsView;
import com.community.process._1010.dao.vo.ProcessFoodItemIngredientsVo;
import com.community.process._1010.dao.vo.ProcessIngredientsVo;
import com.community.process._1010.domains.ProcessIngredientsDTO;
import com.community.process._1010.domains.ProcessIngredientsDTO;
import com.community.process._1010.service.ProcessIngredientsService;
import com.oneadds.lowcode.dto.PageListData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 到餐加工食材 前端控制器
 *
 * @author Zbs
 * @since 2024-09-05
 */
@RestController
@Tag(name = "到餐加工食材")
@RequestMapping("/process/ingredients")
@RequiredArgsConstructor
public class ProcessIngredientsController {

    private final ProcessIngredientsService processIngredientsService;

    @PostMapping("/addIngredients")
    @Operation(summary = "添加食材")
    public CommonResult<String> addIngredients(@RequestBody @Valid ProcessIngredientsDTO.IngredientsAdd dto) {
        this.processIngredientsService.addIngredients(dto);
        return CommonResult.success("");
    }

    @PostMapping("/updateIngredients")
    @Operation(summary = "更新食材")
    public CommonResult<String> updateIngredients(@RequestBody @Valid ProcessIngredientsDTO.IngredientsUpdate dto) {
        this.processIngredientsService.updateIngredients(dto);
        return CommonResult.success("");
    }

    @PostMapping("/deleteIngredients")
    @Operation(summary = "删除食材")
    public CommonResult<String> deleteIngredients(@RequestBody @Valid ProcessIngredientsDTO.IngredientsDelete dto) {
        this.processIngredientsService.deleteIngredients(dto);
        return CommonResult.success("");
    }

    @PostMapping("/getIngredientPageList")
    @Operation(summary = "获取食材列表")
    public CommonResult<PageListData<ProcessIngredientsVo>> getIngredientPageList(@RequestBody @Valid ProcessIngredientsDTO.IngredientsPageSearch dto) {
        PageListData<ProcessIngredientsVo> view = this.processIngredientsService.getIngredientPageList(dto);
        return CommonResult.success(view);
    }

    @PostMapping("/getIngredientById/{id}")
    @Operation(summary = "获取食材详情")
    public CommonResult<ProcessIngredientsView> getIngredientById(@PathVariable Long id) {
        ProcessIngredientsView view = this.processIngredientsService.getIngredientById(id);
        return CommonResult.success(view);
    }

}

